package com.ganbo.thread.wait;


class A extends Thread {

    private Object lock;

    public A(Object o) {
        this.lock = o;
    }

    @Override
    public void run() {
        synchronized (lock) {
            System.out.println("aaaaaaaaaaaaaa  stert");
            try {
                lock.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("aaaaaaaaaaa   end");
        }
    }
}

class B extends Thread {

    private Object lock;

    public B(Object o) {
        this.lock = o;
    }

    @Override
    public void run() {
        synchronized (lock) {
            System.out.println("bbbbbbbbbb  stert");
            lock.notify();
            System.out.println("bbbbbbbbbb   end");
        }
    }
}

public class NotifyDemo {

    public static void main(String[] args) throws InterruptedException {
        Object o = new Object();
        new A(o).start();
        Thread.sleep(2000);
        new B(o).start();
    }

}
